//
//  GPSTrainingCarryPhoneViewController.swift
//  DaRings
//
//  Created by 魔样科技 on 2022/12/7.
//

import Foundation
import MYModule

open class GPSTrainingCarryPhoneViewController: ViewController {
    
    public var type: TrainingType = .unknown
    
    open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigation.bar.isHidden = true
    }

    open override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.navigation.bar.isHidden = false
    }
    
    open override func makeUI() {
        super.makeUI()
        
        self.view.addSubview(self.okButton)
        self.okButton.snp.makeConstraints { make in
            make.height.equalTo(50)
            make.leading.equalTo(50)
            make.centerX.equalToSuperview()
            if #available(iOS 11.0, *) {
                make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom).offset(-50)
            } else {
                make.bottom.equalTo(-50)
            }
            
        }
        
        self.view.addSubview(self.contentLabel)
        self.contentLabel.snp.makeConstraints { make in
            
            var bottom = -58
            if UIScreen.main.bounds.width <= 375 {
                bottom = -28
            }
            
            make.bottom.equalTo(self.okButton.snp.top).offset(bottom)
            make.leading.equalTo(30)
            make.trailing.equalTo(-30)
            
        }
        
        self.view.addSubview(self.titleLabel)
        self.titleLabel.snp.makeConstraints { make in
            make.leading.equalTo(self.contentLabel.snp.leading)
            make.trailing.equalTo(-30)
            make.bottom.equalTo(self.contentLabel.snp.top).offset(-15)
        }
        
        self.view.addSubview(self.iconImageView)
        self.iconImageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.greaterThanOrEqualToSuperview().offset(20)
            
            var bottom = -87
            if UIScreen.main.bounds.width <= 375 {
                bottom = -47
            }
            make.bottom.equalTo(self.titleLabel.snp.top).offset(bottom)
        }
    }
    
    open override func bindViewModel() {
        super.bindViewModel()
        
        self.okButton.rx.tap.subscribe(onNext: { [weak self] _ in
            guard let self = self else { return }
            DispatchQueue.main.async {
                let vc = GPSTrainingMapViewController()
                vc.type = self.type
                self.navigationController?.pushViewController(vc, animated: true)
            }
        }).disposed(by: rx.disposeBag)
    }
    
    //MARK: - lazy load -
    private lazy var iconImageView: ImageView = {
        let view = ImageView()
        view.contentMode = .scaleAspectFit
        view.image = UIImage(named: "img_carry_correctly")
        return view
    }()
    
    private lazy var titleLabel: Label = {
        let label = Label()
        label.textColor = UIColor.assist_222222
        label.font = .boldSystemFont(ofSize: 24)
        label.text = "gps_training_advance_reminder_title".language
        label.numberOfLines = 0
        return label
    }()
    
    private lazy var contentLabel: Label = {
        let label = Label()
        label.textColor = UIColor.assist_A9A9A9
        label.font = .boldSystemFont(ofSize: 16)
        label.text = "gpstraining_advance_reminder_content".language
        label.numberOfLines = 0
        return label
    }()
    
    private lazy var okButton: Button = {
        let button = Button()
        button.setTitle("gps_training_advance_reminder_btn_title".language, for: .normal)
        button.setTitleColor(UIColor.assist_FFFFFF, for: .normal)
        button.backgroundColor = UIColor.GPSTraining.theme
        button.cornerRadius = 25
        return button
    }()

}
